import { createApp } from "vue";
import App from "./App.vue";

// 引入全局样式
import "./assets/css/global.css";
import "./assets/styles/layouts.less"; // 引入布局样式
// 引入路由
import router from "./router";
// 引入vue-i18n
import i18n, { loadLocalData } from "./i18n";
// 引入element-plus
import ElementPlus from "element-plus";
// 引入element-plus 语言
import zhCn from "element-plus/es/locale/lang/zh-cn";
import en from "element-plus/es/locale/lang/en";
// 引入element-plus样式
// import "element-plus/dist/index.css";
// 引入element-plus扩展样式
import "@/assets/styles/index.scss";
import "@/assets/css/element-ext.css";
// import "@/styles/index.scss";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
// 引入iconfont
import "@/assets/iconfont/iconfont.js";
// 引入iconfont样式
import "@/assets/iconfont/iconfont.css";
// 引入vxetable
// import VXETable from "vxe-table";
// import "vxe-table/lib/style.css";
import VxeUIAll from "vxe-pc-ui";
import "vxe-pc-ui/es/style.css";

import VxeUITable from "vxe-table";
import "vxe-table/es/style.css";

import VxeUIDesign from "vxe-design";
import "vxe-design/lib/style.css";

import zhCNt from "vxe-table/lib/locale/lang/zh-CN"; // 中文(简体)
import enUSt from "vxe-table/lib/locale/lang/en-US"; // 英语(美国)
VxeUITable.setI18n("zh-CN", zhCNt);
VxeUITable.setI18n("en-US", enUSt);

// 设置全局api
import api from "@/api";
// 设置全局tool
import tool from "@/utils/tool";
// 设置全局EXUtils
import XEUtils from "xe-utils";
// 引入全局组件
import zzComp from "./zzComp";
// 设置全局常量
import constants from "@/constants";

import FcDesigner from "@form-create/designer";

const app = createApp(App);

app.config.globalProperties.$API = api;
app.config.globalProperties.$TOOL = tool;
app.config.globalProperties.$XEUtils = XEUtils;
app.config.globalProperties.$CONS = constants;
// 设置全局 i18n 函数
app.config.globalProperties.$t = i18n.global.t;
app.config.globalProperties.$i18n = i18n.global;

// 根据localStorage中的语言设置选择语言包
const savedLanguage = localStorage.getItem("language") || "zh-CN";
const currentLocale = savedLanguage === "zh-CN" ? zhCn : en;
loadLocalData(savedLanguage);
VxeUITable.setLanguage(savedLanguage);

app
  .use(router)
  .use(i18n)
  .use(VxeUIAll)
  .use(VxeUITable)
  // .use(VxeUIDesign)
  .use(ElementPlus, { zIndex: 3000, locale: currentLocale })
  .use(FcDesigner)
  .use(FcDesigner.formCreate)
  .use(zzComp);

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.mount("#app");
